package qeug.shsh.opplugin;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.datamodel.events.ChangeData;
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
import kd.bos.form.plugin.AbstractFormPlugin;

//表头费用承担公司赋值分摊分录中的费用承担公司逻辑
//使用单据：差旅报销单，费用报销单，付款申请单
public class CostCompanyPlugin extends AbstractFormPlugin {

    @Override
    public void propertyChanged(PropertyChangedArgs e) {
        super.propertyChanged(e);
        String fieldKey = e.getProperty().getName();
        if ("costcompany".equals(fieldKey)){
            //费用承担公司
            ChangeData[] changeSet = e.getChangeSet();
            ChangeData changeData = changeSet[0];
            DynamicObject costCompany = (DynamicObject) changeData.getNewValue();//新值
            DynamicObject dataEntity = this.getModel().getDataEntity(true);
            DynamicObjectCollection expenseEntryEntityCollection = dataEntity.getDynamicObjectCollection("expenseentryentity_rule");//分摊明细分录
            for (DynamicObject expenseEntryEntity : expenseEntryEntityCollection) {
                expenseEntryEntity.set("entrycostcompany_orgrule", costCompany);//分摊中的费用承担公司
            }
            this.getView().updateView("expenseentryentity_rule");
        }
    }
}
